//
//  LotteryNumCell.m
//  TicketPlan
//
//  Created by tangang on 2017/12/22.
//  Copyright © 2017年 tangang. All rights reserved.
//

#import "LotteryNumCell.h"

@implementation LotteryNumCell{
    QXLable   *labNum;
    UIImageView *imageNum;
    CGFloat     size;
}

- (instancetype)initWithFrame:(CGRect)frame{
    if (self=[super initWithFrame:frame]) {
        WS(weakSelf);
        size=frame.size.width-4;
        
        imageNum=[[UIImageView alloc]init];
        [self.contentView addSubview:imageNum];
        [imageNum mas_makeConstraints:^(MASConstraintMaker *make) {
            make.edges.equalTo(weakSelf.contentView)
            .with.insets(UIEdgeInsetsMake(2, 2, 2, 2));
        }];
        
        labNum=[[QXLable alloc]init];
        labNum.textColor=[UIColor whiteColor];
        labNum.textAlignment=NSTextAlignmentCenter;
        [self.contentView addSubview:labNum];
        [labNum mas_makeConstraints:^(MASConstraintMaker *make) {
            make.edges.equalTo(weakSelf.contentView)
            .with.insets(UIEdgeInsetsMake(2, 2, 2, 2));
        }];
        
        
    }
    return self;
}

- (void)setDownTitle:(NSString *)title andType:(LotteryNumType)type{
    imageNum.hidden=YES;
    labNum.hidden=NO;
    labNum.font=[UIFont systemFontOfSize:10];
    labNum.text=title;
    labNum.layer.masksToBounds=YES;
    labNum.layer.cornerRadius=3;
    labNum.textColor=DEFAULTTEXTBLACKCOLOR;
}

- (void)setTitle:(NSString *)title andType:(LotteryNumType)type{
    if (type==LotteryNumTypeCarPK10||type==LotteryNumTypeLuckyAirship) {
        [self imageTitle:title];
    }else if (type==LotteryNumTypeLottery){
        [self bgImageTitle:title];
    }else{
        [self blueTitle:title];
    }
}

- (void)setTopTitle:(NSString *)topTitle andType:(LotteryNumType)type andTitleColor:(UIColor *)textColor{
    if (type==LotteryNumTypeLottery){
        [self bgImageTitle:topTitle];
    }else{
        [self topText:topTitle andTextColor:textColor];
    }
}

- (void)topText:(NSString *)title andTextColor:(UIColor *)textColor{
    imageNum.hidden=YES;
    labNum.hidden=NO;
    labNum.textColor=textColor;
    labNum.text=title;
    labNum.font=[UIFont systemFontOfSize:18];
    labNum.textAlignment=NSTextAlignmentCenter;
}


- (void)setTitle:(NSString *)title andBgColor:(UIColor *)color andTextColor:(UIColor *)textColor{
    imageNum.hidden=YES;
    labNum.hidden=NO;
    labNum.layer.masksToBounds=YES;
    labNum.layer.cornerRadius=size/2.0;
    labNum.backgroundColor=color;
    labNum.text=title;
    labNum.textColor=textColor;
}

- (void)blueTitle:(NSString *)title{
    imageNum.hidden=YES;
    labNum.hidden=NO;
    labNum.layer.masksToBounds=YES;
    labNum.layer.cornerRadius=size/2;
    if ([title isEqualToString:@"+"]||[title isEqualToString:@"="]) {
        labNum.backgroundColor=[UIColor whiteColor];
        labNum.textColor=DEFAULTTEXTBLACKCOLOR;
        labNum.font=[UIFont systemFontOfSize:15];
    }else{
        labNum.backgroundColor=NAVCOLOR;
        labNum.textColor=[UIColor whiteColor];
        labNum.font=[UIFont systemFontOfSize:13];
    }
    labNum.text=title;
    
}

#define redBalls @[@"01", @"02", @"07", @"08", @"12", @"13", @"18", @"19", @"23", @"24", @"29", @"30", @"34", @"35", @"40", @"45", @"46"]
#define blueBalls @[@"03", @"04", @"09", @"10", @"14", @"15", @"20", @"25", @"26", @"31", @"36", @"37", @"41", @"42", @"47", @"48"]
#define greenBalls @[@"05", @"06", @"11", @"16", @"17", @"21", @"22", @"27", @"28", @"32", @"33", @"38", @"39", @"43", @"44", @"49"]

- (void)bgImageTitle:(NSString *)title{
    imageNum.hidden=NO;
    labNum.hidden=NO;
    labNum.backgroundColor=[UIColor clearColor];
    labNum.text=title;
    [labNum setFont:[UIFont systemFontOfSize:10]];
    labNum.textColor=DEFAULTTEXTBLACKCOLOR;
    if ([redBalls containsObject:title]) {
        [imageNum setImage:[UIImage imageNamed:@"redBall"]];
    }else if ([blueBalls containsObject:title]){
        [imageNum setImage:[UIImage imageNamed:@"blueBall"]];
    }else if([greenBalls containsObject:title]){
        [imageNum setImage:[UIImage imageNamed:@"greenBall"]];
    }else{
        
        [imageNum setImage:nil];
    }
}


- (void)setTitleColor:(UIColor *)color{
    labNum.textColor=color;
}

- (void)imageTitle:(NSString *)title{
    imageNum.hidden=NO;
    labNum.hidden=YES;
    [imageNum setImage:[UIImage imageNamed:[NSString stringWithFormat:@"carPK%@",title]]];
}

- (void)setFount:(NSInteger)fount{
    labNum.font=[UIFont systemFontOfSize:fount];
}

- (void)setBGColor:(UIColor *)color{
    labNum.backgroundColor=color;
}

@end
